subroutine r2abij_t2efij_iefab2_ri_g(r2, t2, &
              rivv, rivv2, icore, fact, icoreg)
!
use mod_ri
use mod_size
use mod_iop
use mod_orbit
use mod_ioff 
use mod_symm
implicit none
!
real*8, intent(in) :: fact
real*4, intent(in) :: r2(*)
real*4, intent(in) :: rivv(*), rivv2(*)
!
real*4, intent(inout) :: t2(*), icore(*)
real*4, intent(inout) :: icoreg(*)
!
integer :: i, j, a, b, nsize, i0, i1, i2, i3, i4, i5, i6, i7
integer :: c, d, iin1, iin2, iout1, iout2, iout3, iout4
integer, external :: idsymsoc
character*8 file1, file2
real*8, external :: nrm2so
!this is to do r2 = r2 + 0.5*t2(efij)*iefab
igpu = 0
if(prec==8) then 
   file1 = 'ABCDAB1_'
   file2 = 'ABCDAB2_'
elseif(prec==4) then  
   file1 = 'ABCDAB1S'
   file2 = 'ABCDAB2S'
endif   
i0 = 1                  ! t+
i1 = i0 + nvvoo*isd     ! t-
i2 = i1 + nvvoo*isd     ! tmp+
i3 = i2 + nvvoo*isd     ! tmp-
i4 = i3 + nvvoo*isd     ! itmp 
i5 = i4 + nvvoo*isd     ! icore 
! t-
!write(6,*)'test1', nrm2so(nvvoo, icore(i0), 1)
!write(6,*)'test2', nrm2so(nvvoo, icore(i1), 1)
!write(6,*)'test3', nrm2so(nvvoo, icore(i2), 1)
!write(6,*)'test4', nrm2so(nvvoo, icore(i3), 1)
!write(6,*)'test5', nrm2so(nvvoo, icore(i4), 1)
!write(6,*)'test6', nrm2so(nvvoo, icore(i5), 1)
call iassymso(t2, icore(i1), 1, vrta, vrta, popa, popa, 1)
call icompso(icore(i1), icore(i0), vrta, vrta, 1, 0, popa, popa, 0, 1, 1)
 nsize = idsymsoc(1, vrta, vrta, 0, popa, popa, 0)
if(ldebug) then  
 write(6,*)'norm of t-', nrm2so(nsize, icore(i0), 1)
endif
! t+
call isymtrso(t2, icore(i1), vrta, vrta, 1, 1, popa, popa, 1, 0, 1)
nsize = idsymsoc(1, vrta, vrta, 1, popa, popa, 1)
call axpyso(nsize, 1.d0, t2, 1, icore(i1), 1)
call icompso(icore(i1), icore(i2), vrta, vrta, 1, 2, popa, popa, 1, 1, 1)
call icompso(icore(i2), icore(i1), vrta, vrta, 2, 1, popa, popa, 1, 2, 1)
 nsize = idsymsoc(1, vrta, vrta, 2, popa, popa, 2)
if(ldebug) then  
 write(6,*)'norm of t+', nrm2so(nsize, icore(i1), 1)
endif

!--------  t-*abcd-
nsize = idsymsoc(1, vrta, vrta, 0, popa, popa, 0)
call myicopy_g(icore(i0), icoreg(i0), nsize)
if(ldebug) then  
write(6,*)'finished copy'
endif
igpu = 1
call VmnpqVmnrs_to_Vpqrs_ri_in(icoreg(i0), icoreg(i2), 1, 1, vrta, vrta, 0, &
                popa, popa, 0, vrta, vrta, 0, icoreg(i1), 1, 0.5d0, 0.d0, &
                rivv, rivv2) 
nsize = idsymsoc(1, vrta, vrta, 0, popa, popa, 0)
call myicopy_c(icoreg(i1), icore(i4), nsize)
igpu = 0
!call VmnpqVmnrs_to_Vpqrs_ri_in(icore(i0), icore(i5), 1, 1, vrta, vrta, 0, &
!                popa, popa, 0, vrta, vrta, 0, icore(i4), 1, 0.5d0, 0.d0, &
!                rivv, rivv2) 
call itranspso(icore(i4), icore(i2), popa, popa, 0, vrta, vrta, 0, 1) 
!call VpqmnVmnrs_to_Vpqrs(iabcd(ioi6(1)), icore(i0), 1, 1, vrta, vrta, 0, &
!                 vrta, vrta, 0, popa, popa, 0, icore(i2), 1, 0.5d0, 0.d0)
 nsize = idsymsoc(1, vrta, vrta, 0, popa, popa, 0)
if(ldebug) then  
 write(6,*)'norm of tmp abcd 1', nrm2so(nsize, icore(i2), 1)
endif

!--------  t+*abcd+
nsize = idsymsoc(1, vrta, vrta, 2, popa, popa, 2)
call myicopy_g(icore(i1), icoreg(i0), nsize)
igpu = 1
call VmnpqVmnrs_to_Vpqrs_ri_in(icoreg(i0), icoreg(i2), 1, 1, vrta, vrta, 2, &
                popa, popa, 2, vrta, vrta, 2, icoreg(i1), 1, 0.5d0, 0.d0, &
                rivv, rivv2) 
nsize = idsymsoc(1, vrta, vrta, 2, popa, popa, 2)
call myicopy_c(icoreg(i1), icore(i4), nsize)
igpu = 0
call itranspso(icore(i4), icore(i3), popa, popa, 2, vrta, vrta, 2, 1) 
!call VpqmnVmnrs_to_Vpqrs(iabcd(ioi6(2)), icore(i1), 1, 1, vrta, vrta, 2, &
!                 vrta, vrta, 2, popa, popa, 2, icore(i3), 1, 0.5d0, 0.d0)
 nsize = idsymsoc(1, vrta, vrta, 2, popa, popa, 2)
if(ldebug) then  
 write(6,*)'norm of tmp abcd 2', nrm2so(nsize, icore(i3), 1)
endif

!-------expand r-  to icore(i0)
call iexpso(icore(i2), icore(i1), vrta, vrta, 0, 1, popa, popa, 0, 0, 1)
call iexpso(icore(i1), icore(i0), vrta, vrta, 1, 0, popa, popa, 0, 1, 1)
! nsize = idsymsoc(1, vrta, vrta, 1, popa, popa, 1)
! write(6,*)'norm of test abcd 1', nrm2so(nsize, icore(i0), 1)

!-------expand r+  to icore(i1)                                       
call iexpso(icore(i3), icore(i2), vrta, vrta, 2, 0, popa, popa, 2, 1, 1)
call iexpso(icore(i2), icore(i1), vrta, vrta, 2, 1, popa, popa, 1, 0, 1)
!nsize = idsymsoc(1, vrta, vrta, 1, popa, popa, 1)
!write(6,*)'norm of test abcd 2', nrm2so(nsize, icore(i1), 1)
! t- + t+
nsize = idsymsoc(1, vrta, vrta, 1, popa, popa, 1)
call axpyso(nsize, 1.d0, icore(i1), 1, icore(i0), 1)
!nsize = idsymsoc(1, vrta, vrta, 1, popa, popa, 1)
!write(6,*)'norm of test abcd', nrm2so(nsize, icore(i0), 1)
!
call axpyso(nioi32, fact*2.d0, icore(i0), 1, r2(ioi3(2)), 1)
return
end
